package com.xiumu.service.blog.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiumu.common.core.page.PageQuery;
import com.xiumu.dao.blog.BlogCategoryDao;
import com.xiumu.pojo.blog.dto.BlogCategoryDTO;
import com.xiumu.pojo.blog.entity.BlogCategory;
import com.xiumu.pojo.blog.query.BlogCategoryQuery;
import com.xiumu.service.blog.BlogCategoryService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 博客分类表 Service 接口实现
 *
 * @author XiuMu
 * @Date 2023-01-29 17:59:59
 */
@Service
public class BlogCategoryServiceImpl extends ServiceImpl<BlogCategoryDao, BlogCategory> implements BlogCategoryService {
    @Override
    public Page<BlogCategory> listPage(PageQuery<BlogCategoryQuery, BlogCategory> pageQuery) {
        return this.baseMapper.selectPage(pageQuery.toPage(), pageQuery.getCondition());
    }

    @Override
    public List<BlogCategory> listByBlogCategory(BlogCategoryQuery blogCategory) {
        return this.baseMapper.selectByBlogCategory(blogCategory);
    }

    @Override
    @Transactional
    public boolean create(BlogCategoryDTO blogCategoryDTO) {
        BlogCategory blogCategory = BeanUtil.toBean(blogCategoryDTO, BlogCategory.class);
        return this.save(blogCategory);
    }

    @Override
    @Transactional
    public boolean updateById(BlogCategoryDTO blogCategoryDTO, Long id) {
        BlogCategory blogCategory = BeanUtil.copyProperties(blogCategoryDTO, BlogCategory.class);
        blogCategory.setId(id);
        return updateById(blogCategory);
    }
}




